const express = require('express')
const bodyParser = require('body-parser')

const app = express()


//配置
require('./mongodb/mongodb')   //数据库连接
require('./config/http')(app)  //解决跨域

//中间件配置
app.use(express.json())   //让express可以接收json请求
app.use(bodyParser.urlencoded({extended:false}))   //固定写法
app.use(bodyParser.json())    //如果有json的话，可以解析json

//加载路由
const safeCode = require('./api/safeCode')
const adminRouter = require('./api/admin')
const randomAccount = require('./api/randomAccount')

//注册路由
app.use("/api/safecode",safeCode)
app.use("/api/admin",adminRouter)
app.use("/api/randomAccount",randomAccount)

app.listen(3000,err=>{
    if(err){
        throw err
    }

    console.log(`Server is running at http://localhost:3000`);
})